package test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo {


	public static void main(String[] args) {
/*		String[] split = str.split("/");
		for (String string : split) {
			System.out.println(string);
			String[] split2 = string.split(",");
			for (String string2 : split2) {
				System.out.println(string2+"!!!!!!!!!!!!!");
			}
			System.out.println("------------------------------------");
		}*/


		String str="tom_1-jack_1-李四_1-";
		//String st="tom_1-jack_1-李四_1-";
		String str1="";
		Map<String, Object> str3 = getStr(str,"fssd","1");
		System.out.println("tempString:"+str3.get("tempString"));
		System.out.println("tempCarNum:"+str3.get("tempCarNum"));
		
/*		Map<String, Object> str2 = getStr(str,"jack","1");
		System.out.println(str2.get("tempString"));
		System.out.println(str2.get("tempCarNum"));
		
		
		Map<String, Object> str4 = getStr(str,"李四","1");
		System.out.println(str4.get("tempString"));
		System.out.println(str4.get("tempCarNum"));
		
		Map<String, Object> str5 = getStr(str1,"李四","1");
		System.out.println(str5.get("tempString"));
		System.out.println(str5.get("tempCarNum"));*/

		Map<String, Object> str5 = getStr(str1,"李四","1");
		System.out.println(str5.get("tempString"));
		System.out.println(str5.get("tempCarNum"));
		
		List<String> list=new ArrayList<>();
		list.add("fsa");
		list.add("fsa");
		list.add("fsa");
		System.out.println(list.size());
		
		
		String adsa="fsaf/afsa/afsafagfds/1dss";
		String[] split = adsa.split("/");
		for (String string : split) {
			System.out.println(string+"@@@@@@@@@@");
		}
		System.out.println("@@@@@@@@@@"+split[split.length-1]);
	}



	
	public static Map<String, Object> getStr(String str,String name,String num) {
		// map里面封装俩个 值. 
		// 一个是全字符串  tempString
		//,另外一个是购物车的数量,并不是单个商品的数量 tempCarNum
		Map<String, Object> map=new HashMap<>();
		int tempCarNum=0;								

		if (!str.trim().equals("")) {
			String[] split = str.split("-");
			//System.out.println("length:"+split.length);
			tempCarNum=split.length;
			String test="";
			int tt=0;
			for (String string : split) {
				//System.out.println(string);
				String[] split2 = string.split("_");
				for (int i = 0; i < split2.length;) {
					if (split2[0].trim().equals(name) ) {
						int temp=Integer.parseInt(split2[1]);
						int tempnum=Integer.parseInt(num);
						tempnum=temp+tempnum;
						split2[1]=String.valueOf(tempnum);
						test=test+split2[0]+"_"+split2[1]+"-";
						//System.out.println(test+"1111111111");
						break;
					}else {
						test = test + split2[0] + "_" + split2[1] + "-";
						tt++;
						//System.out.println(test+"22222222222222@@@@@@@@@"+tt);
						break;
					}
				}

			}
			//System.out.println(tt);
			if (tt==tempCarNum) {
				test=str+"-"+name+"_"+num+"-";
				tempCarNum++;
			}else {
				test=test;
			}
			map.put("tempString",test );
			map.put("tempCarNum",tempCarNum );
			//System.out.println(test);
			System.out.println("---------------------");
			return map;
		}else {
			String tet=name+"_"+num+"-";
			map.put("tempString",tet );
			map.put("tempCarNum",1 );
			System.out.println("++++++++++++++++++++++++");
			return map;
		}


	}


}
